import 'package:awak/common/repository/topic_repository.dart';
import 'package:awak/common/repository/user_repository.dart';
import 'package:awak/common/repository/room_repository.dart';
import 'package:awak/common/repository/comment_repository.dart';

/// 数据初始化器
/// 负责初始化应用的基础数据，包括用户、房间、评论等
class DataInitializer {
  static final DataInitializer _instance = DataInitializer._internal();
  factory DataInitializer() => _instance;
  DataInitializer._internal();

  final UserRepository _userRepository = UserRepository();
  final RoomRepository _roomRepository = RoomRepository();
  final CommentRepository _commentRepository = CommentRepository();
  final TopicRepository _topicRepository = TopicRepository();

  /// 初始化所有基础数据（现在数据在 db_helper.dart 中创建）
  Future<void> initializeAllData() async {
    print('Data initialization is now handled in db_helper.dart');
  }

  /// 初始化用户数据（现在在 db_helper.dart 中处理）
  Future<void> initializeUsers() async {
    print('User data initialization is now handled in db_helper.dart');
  }

  /// 初始化房间数据（现在在 db_helper.dart 中处理）
  Future<void> initializeRooms() async {
    print('Room data initialization is now handled in db_helper.dart');
  }

  /// 初始化评论数据（现在在 db_helper.dart 中处理）
  Future<void> initializeComments() async {
    print('Comment data initialization is now handled in db_helper.dart');
  }

  /// 初始化主题数据（现在在 db_helper.dart 中处理）
  Future<void> initializeTopics() async {
    print('Topic data initialization is now handled in db_helper.dart');
  }

  /// 清除所有数据（用于测试或重置）
  Future<void> clearAllData() async {
    try {
      // 注意：这里需要根据实际的数据库清除方法来实现
      // 目前只是打印日志
      print('Data clearing functionality needs to be implemented');
    } catch (e) {
      print('Error clearing data: $e');
    }
  }

  /// 检查数据是否已初始化
  Future<bool> isDataInitialized() async {
    try {
      final users = await _userRepository.getAllUsers();
      final rooms = await _roomRepository.getAllRooms();
      final comments = await _commentRepository.getAllComments();
      final topics = await _topicRepository.getAllTopics();
      return users.isNotEmpty && rooms.isNotEmpty && comments.isNotEmpty && topics.isNotEmpty;
    } catch (e) {
      print('Error checking data initialization status: $e');
      return false;
    }
  }
}
